package com.yunqing.restkeeper.operator.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yunqing.restkeeper.common.utils.Result;
import com.yunqing.restkeeper.operator.api.entity.OperatorUser;
import com.yunqing.restkeeper.operator.api.service.IOperatorUserService;
import com.yunqing.restkeeper.operator.web.vo.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员的登录接口
 */
@RestController
@RefreshScope //配置中心的自动刷新
@Slf4j
@Tag(name = "管理员相关接口")
public class UserController {


    @Value("${server.port}")
    private String port;

    @DubboReference(version = "1.0.0", check = false)
    private IOperatorUserService operatorUserService;

    @GetMapping(value = "/echo")
    public String echo() {
        return "i am from port: " + port;
    }


    @GetMapping("/pageList/{page}/{pageSize}")
    public IPage<OperatorUser> findListByPage(@PathVariable("page") int pageNum,
                                              @PathVariable("pageSize") int pageSize,
                                              @RequestParam("name") String name) {

//        IPage<OperatorUser> page = new Page<OperatorUser>(pageNum,pageSize);
//        log.info("管理员数据分页查询："+ JSON.toJSONString(page));
//        return operatorUserService.page(page);
        return operatorUserService.queryPageByName(pageNum, pageSize, name);
    }

    @Operation(summary = "登录校验")
    @PostMapping("/login")
    public Result login(@RequestBody LoginVO loginVO){
        return operatorUserService.login(loginVO.getLoginName(),loginVO.getLoginPass());
    }
}
